package com.xm.xmds1705083.service.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xm.xm.dto.ResultDto;
import com.xm.xm.dto.SearchDto;
import com.xm.xm.util.ErrorCode;
import com.xm.xmds1705083.service.mapper.DuoduoAreaMapper;
import com.xm.xmds1705083.service.model.DuoduoArea;
import com.xm.xmds1705083.service.service.DuoduoAreaService;
import net.sf.json.JSONObject;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.List;

/**
 * 杭州新苗网络科技有限公司
 * @author meihf
 * @date 2017/06/14
 * @description
*/ 
@Service("duoduoAreaService")
public class DuoduoAreaServiceImpl extends ServiceImpl<DuoduoAreaMapper,DuoduoArea> implements DuoduoAreaService {

    @Autowired
    DuoduoAreaMapper duoduoAreaMapper;

    @Override
    public ResultDto findById(SearchDto searchDto) {
        ResultDto resultDto = new ResultDto();
        JSONObject filed = searchDto.getFiled();
        searchDto.setPageNo((searchDto.getPageNo()-1)*searchDto.getPageSize());
        try {
             if (!filed.has("pid")){
                  resultDto.setMsg(ErrorCode.E10011);
                  resultDto.setCode(ErrorCode.C10011);
                  return resultDto;
              }else{
                  int pid = filed.getInt("pid");
                 RowBounds rowBounds = new RowBounds(searchDto.getPageNo(),searchDto.getPageSize());
                  EntityWrapper entityWrapper = new EntityWrapper();
                  entityWrapper.where(" pid={0} ",pid);
                  List<DuoduoArea> duoduoAreaList = duoduoAreaMapper.selectPage(rowBounds,entityWrapper);
                  if (duoduoAreaList.size()==0){
                      resultDto.setCode(ErrorCode.C11001);
                      resultDto.setMsg(ErrorCode.E11001);
                  }else {
                      resultDto.setData(duoduoAreaList);
                      resultDto.setMsg("查询成功！");
                  }
              }
        }catch (RuntimeException e ){
            e.printStackTrace();
            resultDto.setCode(ErrorCode.C10013);
            resultDto.setMsg(ErrorCode.E10013);
        }
        return resultDto;
    }
}

